/**
 * Created by zhangwenlei on 2017/4/27.
 */
var express=require('express');
var path=require('path');
var router=express.Router();
var spawn=require('child_process').spawn;

router.post('/',function (req, res) {
    if(this.child){
        this.child.kill('SIGTERM');
        this.child = null;
    }
    this.child=spawn('node',["index.js"],{cwd:path.join(__dirname,'..','..','mvc-new')});

    child.stdout.on('data', function(data) {
        console.log(data.toString());
    });
    child.stderr.on('data', function(data) {
        console.log(data.toString());
    });
    child.on('exit', function(code) {
        console.log('Child exited with code', code);
    });
    res.end('run success');

});

module.exports=router;